<?php
session_start();
require_once 'config/database.php';
require_once 'includes/functions.php';

// Get featured products
$featured_products = getFeaturedProducts($pdo, 6);

$page_title = "Luxury Home Fragrance";
?>
<?php include 'includes/header.php'; ?>

<?php if (isset($_GET['logged_out']) && $_GET['logged_out'] == '1'): ?>
    <div class="alert alert-success" style="margin: 1rem 0; text-align: center;">
        <i class="fas fa-check-circle"></i> You have been successfully logged out.
    </div>
<?php endif; ?>

<main>
    <!-- Hero Section -->
    <section class="hero">
        <div class="container">
            <h1>Discover Your Signature Scent</h1>
            <p>Luxury home fragrances crafted with artisanal care and sustainable ingredients. Elevate your space with our curated collection of hand-poured candles, reed diffusers, and essential oil blends.</p>
            <div class="hero-actions">
                <a href="/chuan/513i/products/" class="btn btn-primary">Shop Now</a>
                <a href="/chuan/513i/about.php" class="btn btn-outline">Learn More</a>
            </div>
        </div>
    </section>

    <!-- Featured Products -->
    <section class="container">
        <div style="text-align: center; margin: 4rem 0 2rem;">
            <h2>Featured Fragrances</h2>
            <p style="color: #7f8c8d; margin-top: 1rem;">Discover our most popular and exclusive fragrance collections</p>
        </div>
        
        <div class="products-grid">
            <?php foreach ($featured_products as $product): ?>
            <div class="product-card">
                <div class="product-image">
                    <?php
                    // Get appropriate image based on product name
                    $product_images = [
                        'Serenity Candle' => 'assets/images/Serenity Candle.jpg',
                        'Velvet Oud Diffuser' => 'assets/images/Velvet Oud Diffuser.jpg',
                        'Monthly Aura Box' => 'assets/images/Monthly Aura Box.jpg',
                        'Ocean Breeze Candle' => 'assets/images/Ocean Breeze Candle.jpg',
                        'Sandalwood Essential Oil' => 'assets/images/Sandalwood Essential Oil.jpg',
                        'Luxury Gift Set' => 'assets/images/Luxury Gift Set.jpg'
                    ];
                    $image_url = $product_images[$product['name']] ?? 'https://images.unsplash.com/photo-1544947950-fa07a98d237f?w=400&h=300&fit=crop&crop=center';
                    if (strpos($image_url, 'assets/images/') === 0) {
                        $image_url = 'assets/images/' . rawurlencode(basename($image_url));
                    }
                    ?>
                    <img src="<?php echo $image_url; ?>" alt="<?php echo htmlspecialchars($product['name']); ?>">
                    <div class="product-overlay">
                        <a href="products/view.php?id=<?php echo $product['id']; ?>" class="btn btn-outline">View Details</a>
                    </div>
                </div>
                <div class="product-info">
                    <h3><?php echo htmlspecialchars($product['name']); ?></h3>
                    <p><?php echo htmlspecialchars(substr($product['description'], 0, 100)) . '...'; ?></p>
                    <div class="product-price"><?php echo formatPrice($product['price']); ?></div>
                    <button class="btn btn-primary add-to-cart" data-product-id="<?php echo $product['id']; ?>">
                        Add to Cart
                    </button>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
        
        <div style="text-align: center; margin: 3rem 0;">
            <a href="/chuan/513i/products/" class="btn btn-outline">View All Products</a>
        </div>
    </section>

    <!-- Features Section -->
    <section class="features">
        <div class="container">
            <div style="text-align: center; margin-bottom: 3rem;">
                <h2>Why Choose Roielune?</h2>
                <p style="color: #7f8c8d; margin-top: 1rem;">Experience the difference of luxury home fragrances</p>
            </div>
            
            <div class="features-grid">
                <div class="feature">
                    <i class="fas fa-leaf"></i>
                    <h3>Sustainable</h3>
                    <p>Eco-friendly ingredients and packaging sourced from ethical suppliers worldwide.</p>
                </div>
                <div class="feature">
                    <i class="fas fa-palette"></i>
                    <h3>Artisanal</h3>
                    <p>Hand-crafted with care using traditional techniques and premium materials.</p>
                </div>
                <div class="feature">
                    <i class="fas fa-shipping-fast"></i>
                    <h3>Fast Delivery</h3>
                    <p>Premium shipping worldwide with tracking and insurance included.</p>
                </div>
                <div class="feature">
                    <i class="fas fa-gift"></i>
                    <h3>Gift Ready</h3>
                    <p>Beautifully packaged and ready for gifting with personalized messages.</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Newsletter Section -->
    <section style="background: #f8f9fa; padding: 4rem 0;">
        <div class="container">
            <div style="text-align: center; max-width: 600px; margin: 0 auto;">
                <h2>Stay in the Loop</h2>
                <p style="color: #7f8c8d; margin: 1rem 0 2rem;">Subscribe to our newsletter for exclusive offers, new fragrance launches, and seasonal collections.</p>
                <form class="newsletter-form" style="max-width: 400px; margin: 0 auto;">
                    <input type="email" placeholder="Enter your email address" required>
                    <button type="submit">Subscribe</button>
                </form>
            </div>
        </div>
    </section>
</main>

<?php include 'includes/footer.php'; ?>
